Skip to content
This repository has been archived by the owner on Sep 8, 2021. It is now read-only.

Generic Drake/ROS systems + RS Flip Flop example #6

Merged
merged 39 commits into from
Sep 8, 2021
Merged

Conversation

sloretz
Copy link
Owner

@sloretz sloretz commented Nov 14, 2020

This adds generic ROS publisher/subscriber systems as described in RobotLocomotion/drake#9500. It's similar to https://github.com/gizatt/drake_ros_systems , but this uses ROS 2 and matches the LCM publisher/subscriber system's design more closely.

RS Flip Flop example

There's an example of an RS flip flop system that listens to topics /S, and /R and publishes to topics /Q and /Q_not.

To try this example out:

  1. Install ROS Rolling - it might work with other ROS 2 versions, but I haven't tried it
  2. Clone this repo into a colcon workspace
  3. colcon build --packages-select drake_ros_systems
  4. Run one of the rs_flip_flop examples
    • C++ from the build folder: ./build/drake_ros_systems/example/rs_flip_flop
    • Python from the example folder: python3 rs_flip_flop.py
  5. Play with it with some of these commands:

Echo output topics:

$ ros2 topic echo /Q
ros2 topic echo /Q_not

Send values to the input topics

$ ros2 topic pub /S std_msgs/msg/Bool "data: false"
$ ros2 topic pub /S std_msgs/msg/Bool "data: true"
$ ros2 topic pub /R std_msgs/msg/Bool "data: false"
$ ros2 topic pub /R std_msgs/msg/Bool "data: true"

Future enhancements

C++

Python

  • Use pybind11::capsule::get_pointer() when available

Code copying

The generic publisher and subscriber using raw messages was significantly copied from rosbag2_transport: https://github.com/ros2/rosbag2/tree/master/rosbag2_transport but it should probably be change to use these classes (not yet merged ros2/rclcpp#1452)

The Drake boilerplate in RosInterfaceSystem, RosSubscriberSystem, and RosPublisherSystem was significantly copied from the equivalent LCM systems in drake.


This change is Reviewable

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@sloretz sloretz self-assigned this Nov 14, 2020
@sloretz
Copy link
Owner Author

sloretz commented Nov 17, 2020

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Publisher and ROS interface working, subscriber not yet working.

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Contributor

@azeey azeey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! However, I don't understand much of the code in py_serializer.hpp, so another pair of eyes would be welcome.

I have built and tested the example with both the colcon and cmake workflows, and they both work!

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
This adds a way to provide the node name and node options, as well as a
way to externally manage init/shutdown on a context. If the given node
options have a valid context, then DrakeRos won't call init or shutdown
on it. In this way external code can pass init options.

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Adds half a type caster (Python -> C++) for rclpy.qos.QoSProfile to
rclcpp::QoS.
Adds QoS arguments to Python publisher and subscriber systems.
Updates the Python example to pass QoS.

Signed-off-by: Shane Loretz <sloretz@openrobotics.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
@EricCousineau-TRI
Copy link

LGTM! However, I don't understand much of the code in py_serializer.hpp, so another pair of eyes would be welcome.

Placing one pair of 👀 here

@EricCousineau-TRI
Copy link

(Going to use Reviewable tho)

Copy link

@EricCousineau-TRI EricCousineau-TRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 25 files reviewed, 3 unresolved discussions (waiting on @sloretz)


drake_ros_systems/src/python_bindings/py_serializer.hpp, line 30 at r4 (raw file):

{
// Serialize/Deserialize Python ROS types to rclcpp::SerializedMessage
class PySerializer : public SerializerInterface

It's a bit challenging to analyze and review Python code flow in C++.
(Also, pumping stuff back and forth btw the two may be less efficient?)

As my own rule of thumb, anything that calls pybind11s Python C++ API more than 3 times in succession should generally be done in a Python function.

Is it possible for you to relegate this code to Python, and use something like what Drake to does to invoke Python code?

Example:
https://github.com/RobotLocomotion/drake/blob/2baad6f34b12bfea1c583dfd63b0970b7eeb479a/bindings/pydrake/pydrake_pybind.h#L127

https://github.com/RobotLocomotion/drake/blob/2baad6f34b12bfea1c583dfd63b0970b7eeb479a/bindings/pydrake/__init__.py#L77-L80

Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Signed-off-by: Shane Loretz <sloretz@osrfoundation.org>
Copy link
Owner Author

@sloretz sloretz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 27 files reviewed, 3 unresolved discussions (waiting on @EricCousineau-TRI and @sloretz)


drake_ros_systems/src/python_bindings/py_serializer.hpp, line 30 at r4 (raw file):

Previously, EricCousineau-TRI (Eric Cousineau) wrote…

It's a bit challenging to analyze and review Python code flow in C++.
(Also, pumping stuff back and forth btw the two may be less efficient?)

As my own rule of thumb, anything that calls pybind11s Python C++ API more than 3 times in succession should generally be done in a Python function.

Is it possible for you to relegate this code to Python, and use something like what Drake to does to invoke Python code?

Example:
https://github.com/RobotLocomotion/drake/blob/2baad6f34b12bfea1c583dfd63b0970b7eeb479a/bindings/pydrake/pydrake_pybind.h#L127

https://github.com/RobotLocomotion/drake/blob/2baad6f34b12bfea1c583dfd63b0970b7eeb479a/bindings/pydrake/__init__.py#L77-L80

Relegated a bit more to Python in 22880a8

@sloretz
Copy link
Owner Author

sloretz commented Dec 18, 2020

I think this PR is just waiting on review. There's a little bit of test coverage now in the form of linters, a couple integration tests (one for C++, one for Python) and a small unit test for the DrakeRos class.

@sloretz
Copy link
Owner Author

sloretz commented Sep 8, 2021

Most of this is going into https://github.com/RobotLocomotion/drake-ros

I'll merge this and archive this repo.

@sloretz sloretz merged commit 3a96616 into master Sep 8, 2021
@sloretz sloretz deleted the generic_systems branch September 8, 2021 16:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants